package com.koron.housing.info.service;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.bean.query.PageQuery;
import com.koron.housing.info.bean.po.HousingRecord;
import com.koron.housing.info.bean.query.HousingRecordQuery;
import org.koron.ebs.mybatis.SessionFactory;

import java.util.List;

/**
 * 租房记录(HousingRecord)表服务接口
 *
 * @author jzp
 * @since 2022-02-25 17:18:06
 */
public interface HousingRecordService {

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    HousingRecord getById(SessionFactory factory, String id);

    /**
     * 根据房源id和账号查询最新的租房记录
     */
    HousingRecord getNewByHousingIdAndAccount(SessionFactory factory, String infoId, String account);

    /**
     * 查询所有数据
     *
     * @param query 查询条件对象
     * @return 列表结果集
     */
    List<HousingRecord> list(SessionFactory factory, HousingRecordQuery query);

    List<HousingRecord> listByHousingId(SessionFactory factory, String housingId);

    /**
     * 分页查询
     *
     * @param query 分页条件
     * @return 对象列表
     */
    default PageInfo<HousingRecord> page(SessionFactory factory, PageQuery pageQuery, HousingRecordQuery query) {
        PageHelper.startPage(pageQuery.getPage(), pageQuery.getPageSize(), pageQuery.getOrderBy());
        List<HousingRecord> housingRecordList = list(factory, query);
        return new PageInfo<>(housingRecordList);
    }

    /**
     * 新增数据
     *
     * @param housingRecord 实例对象
     * @return 是否成功
     */
    boolean save(SessionFactory factory, HousingRecord housingRecord);

    boolean saveOrUpdate(SessionFactory factory, HousingRecord housingRecord);

    /**
     * 修改数据
     *
     * @param housingRecord 实例对象
     * @return 是否成功
     */
    boolean update(SessionFactory factory, HousingRecord housingRecord);

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    boolean deleteById(SessionFactory factory, String id);

    boolean saveNew(SessionFactory factory, HousingRecord housingRecord);
}
